<template>
  <div class="swiper-container">
    <div class="swiper-wrapper">
        <div class="swiper-slide" v-for="obj in imglist" :key="obj.bannerid">
          <img :src="obj.img">
        </div>
        
    </div>
    <!-- 如果需要分页器 -->
    <!-- <div class="swiper-pagination"></div> -->
    
    <!-- 如果需要导航按钮 -->
    <div class="swiper-button-prev"></div>
    <div class="swiper-button-next"></div>
    
    <!-- 如果需要滚动条 -->
    <div class="swiper-scrollbar"></div>
</div>
</template>

<script>

import Swiper, { Navigation, Pagination ,Autoplay} from 'swiper';
Swiper.use([Navigation,Pagination,Autoplay]);
import "swiper/swiper-bundle.min.css";

export default {
 name:"BannerVue",
 data(){
  return{
    imgs:[]
    
  }
 },
//  真实接口请求-------------
 created() {
    this.$server({
      url: "/banner/list",
    }).then((res) => {
      let data = res.data;
      console.log(data);
      if(data.code==200){
        this.imgs = data.data
      }
    });
  },
  computed:{
    imglist:function(){
      return this.imgs.filter(item=>item.flag)
    }
  },
  // ------------
 mounted(){
    new Swiper ('.swiper-container', {
    // direction: 'vertical', // 垂直切换选项
    loop: true, // 循环模式选项
    autoplay:true,
    
    // 如果需要分页器
    pagination: {
      el: '.swiper-pagination',
    },
    
    // 如果需要前进后退按钮
    navigation: {
      nextEl: '.swiper-button-next',
      prevEl: '.swiper-button-prev',
    },
    
    // 如果需要滚动条
    scrollbar: {
      el: '.swiper-scrollbar',
    },
  })        
 }
}
</script>

<style scoped>
  .swiper {
    width: 100%;
    height: 200px;
  }  
  img{
    width: 100%;
    height: 100%;
 }
</style>